package fastwave.common.auth.service;

import fastwave.common.auth.constant.CacheConstants;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

/**
 * 采用重写父类的方式，提取客户端信息
 */
public class MyClientDetailsService extends JdbcClientDetailsService {

	public MyClientDetailsService(DataSource dataSource) {
		super(dataSource);
	}

	/**
	 * 从数据库获取client信息
	 */
	@Override
	@Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
	public ClientDetails loadClientByClientId(String clientId) {
		return super.loadClientByClientId(clientId);
	}

}
